home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSDEBUG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-24
|
6KB
|
194 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bsdebug.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to assist in debugging.
// It contains array used to store the current file and line number for a
// debugging operation.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
static SIZET acLine[MAX_THREADS];
static PSZ apszModule[MAX_THREADS];
//----------------------------------------------------------------------------
// Description: Get context string.
// This string includes process id, thread id, date/time, and
// module/line number.
// Parameters: pszBuf Buffer for context string. Should be at least
// 160 bytes in length.
// fShort Short context?
// Returns: Pointer to buffer
//----------------------------------------------------------------------------
PSZ FN DebugContext(PSZ pszBuf, BOOL fShort)
{
time_t now = time(NULL);
struct tm *tm = localtime(&now);
TID tid = THREADID - 1;
if (!DebugMode())
{
pszBuf[0] = '\0';
}
else if (fShort)
{
sprintf(pszBuf,
"PID=%08lX TID=%-4ld %2d:%02d:%02d %2d/%02d/%4d\n"
"Module: %-40.40s Line: %u\n",
(ULONG)Pid(), (LONG)THREADID,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900,
apszModule[(SIZET)tid], acLine[tid]);
}
else
{
sprintf(pszBuf,
"PID=%08lX\n"
"TID=%-4ld\n"
"%d:%02d:%02d %2d/%02d/%4d\n"
"Module: %-.40s\n"
"Line: %u\n",
(ULONG)Pid(), (LONG)THREADID,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900,
apszModule[(SIZET)tid], acLine[tid]);
}
return pszBuf;
}
//----------------------------------------------------------------------------
// Description: Get line number of last debug operation.
// Parameters:
// Returns: Line number
//----------------------------------------------------------------------------
SIZET FN DebugLine(void)
{
TID tid = THREADID - 1;
return acLine[(SIZET)tid];
}
//----------------------------------------------------------------------------
// Description: Get debug mode
// Parameters:
// Returns: TRUE if debug mode is active.
//----------------------------------------------------------------------------
BOOL FN_E DebugMode(void)
{
static BOOL fDebug = FALSE;
static BOOL fInit = FALSE;
if (!fInit)
{
fDebug = EnvCheck("__DEBUGGER__", "YES");
fInit = TRUE;
Log(LOG_HIGH, "Debug mode %s enabled.", (fDebug ? "IS": "IS NOT"));
}
return fDebug;
}
//----------------------------------------------------------------------------
// Description: Get module name of last debug operation
// Parameters:
// Returns: Pointer to module name
//----------------------------------------------------------------------------
PCSZ FN DebugModule(void)
{
TID tid = THREADID - 1;
return (PCSZ)(apszModule[(SIZET)tid] ? apszModule[(SIZET)tid]: "unknown");
}
//----------------------------------------------------------------------------
// Description: Set location of debug information
// Parameters: pszModule Module name
// cLine Line number
// Returns: FALSE
//----------------------------------------------------------------------------
BOOL FN_E DebugSetLocation(PSZ pszModule, SIZET cLine)
{
TID tid = THREADID - 1;
PSZ psz;
// Skip path specifier
if ((psz = strchr(pszModule, PATH_SEP)) != NULL)
pszModule = psz+1;
#if OS_UNIX==0
if ((psz = strchr(pszModule, DRIVE_SEP)) != NULL)
pszModule = psz+1;
strupr(pszModule); // Upper case PC names
#endif
acLine[(SIZET)tid] = cLine;
apszModule[(SIZET)tid] = pszModule;
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN DebugTest(SHORT sTest)
{
CHAR szContext[160];
NOTUSED(sTest);
DebugSetLocation(__FILE__,__LINE__);
Output("Location %s,%u\n", DebugModule(), DebugLine());
Output("Context Long:\n%s", DebugContext(szContext, FALSE));
Output("Context Short:\n%s", DebugContext(szContext, TRUE));
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------